$(function () {
    obj.init();
});

var obj = new function () {
    return {
        init: function () {
            this.funObj().addData();
            this.listener();
        },
        listener: function () {
            var $this = this;
            $('.my-btn').click(function () {
                var idStr = $(this).attr('id');
                var pos = idStr.lastIndexOf('_');
                var num = idStr.substring(pos+1);
                $this.funObj().delFile(idStr,num,uid);
            });
            $('#showLog').click(function () {
                $('.hidelog').fadeIn();
                $('#showLog').hide();
                $('#hideLog').show();
            });
            $('#hideLog').click(function () {
                $('.hidelog').fadeOut();
                $('#showLog').show();
                $('#hideLog').hide();
            });
        },
        funObj: function () {
            var $this = this;
            return {
                addData: function () {
                    $.each(users,function (index,user) {
                        var contentStr = '无缴费凭证';
                        if (user.fileInfo == 0){
                                $('#fileList'+user.iUserId+user.iChargeYear).empty().append('无缴费凭证');
                        } else {
                            if (user.fileInfo.sImages){
                                contentStr = '<table style="width: 100%;"><tr><td>'+xhShowFile.showImage({fileArr : user.fileInfo.sImages, id: user.fileInfo.ids,showDelete:false})+'</td></tr>' +
                                    '</table>';
                            }
                            $('#fileList'+user.iUserId+user.iChargeYear).empty().append(contentStr);
                            $('.images').viewer();
                        }
                    });
                },
                delFile:function (idStr,num,uid) {
                    xhExtra.ajaxRequest('school/delFile',{num:num,iUserId:uid}, {check: false}, function (res) {
                        if (xhExtra.checkError(res)) {
                            return false;
                        } else {
                            $('#'+idStr).parent().parent().prev().remove();
                            $('#'+idStr).parent().parent().remove();
                            window.top.xhTop.showSuccess(res.msg);
                        }
                    },);
                },
                changeStatus:function (result,iId) {
                    window.top.swal({
                        showCancelButton: true,
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        showLoaderOnConfirm: true,
                        allowOutsideClick: false,
                        title: '备注',
                        input: 'textarea',
                        preConfirm: function(explain) {
                            return new Promise(function (resolve, reject) {
                                if(!explain){
                                    reject('备注不能为空！');
                                }
                                else {
                                    xhExtra.ajaxRequest('school/checkPayVouCher',{iResult:result,iId:iId,sRemarks:explain}, {check: false}, function (res) {
                                        if (xhExtra.checkError(res)) {
                                            return false;
                                        } else {
                                            window.top.xhTop.showSuccess(res.msg);
                                            location.reload();
                                        }
                                    },);
                                }
                            })
                        }
                    });

                }
                
            }
        }
    }
};
